package com.mentaleye.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.bean.CurriculumTempBean;
import com.mentaleye.biz.CurriculumBiz;
import com.mentaleye.biz.CurriculumTempBiz;
import com.mentaleye.biz.DictionaryBiz;
import com.mentaleye.enums.DictionaryEnums;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Controller
@RequestMapping(value="/curriculumTemp")
public class CurriculumTempController {

	@Autowired private CurriculumTempBiz curriculumTempBiz;
	@Autowired private DictionaryBiz dictionaryBiz;
	@Autowired private CurriculumBiz curriculumBiz;
	
	@RequestMapping(value="/curriculumTempList")
	public ModelAndView list(){
		ModelAndView view = new ModelAndView("tc/curriculumTemp/curriculumTempList");
		Map<Integer,String> classTypeMap = dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_TYPE.getCode());
		Map<Integer,String> classStatus = dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_TEMP_STATUS.getCode());
		view.addObject("classTypeMap",classTypeMap);
		view.addObject("classStatusMap",classStatus);
		view.addObject("classType",JSONObject.toJSONString(classTypeMap));
		view.addObject("classStatus",JSONObject.toJSONString(classStatus));
		
		return view;
	}
	
	@RequestMapping("/curriculumTempListData")
	@ResponseBody
	public String curriculumTempListData(CommonPage commonPage){
		curriculumTempBiz.queryCurriculumTempByPage(commonPage);
		return commonPage.toSHowPage();
	}
	
	@RequestMapping(value = "/curriculumTempEdit")
	public ModelAndView curriculumTempEdit(@RequestParam(value = "curriculumTempNo",required = false) Integer curriculumTempNo){
		ModelAndView view = new ModelAndView("tc/curriculumTemp/curriculumTempEdit");
		view.addObject("classTypeMap",dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_TYPE.getCode()));
		view.addObject("classStatusMap",dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_TEMP_STATUS.getCode()));
		if(curriculumTempNo != null){
			view.addObject("curriculumTemp",curriculumTempBiz.getCurriculumTempByNo(curriculumTempNo));
		}
		return view;
	}
	
	@RequestMapping(value="/save")
	@ResponseBody
	public String save(CurriculumTempBean curriculumTempBean){
		return JSONObject.toJSONString(curriculumTempBiz.editCurriculumTemp(curriculumTempBean));
	}
	
	@RequestMapping(value="delete")
	@ResponseBody
	public String delete(@RequestBody List<Integer> ids){
		return JSONObject.toJSONString(curriculumTempBiz.deleteCurriculumTemp(ids));
	}
	
	@RequestMapping(value="/getRelate")
	public ModelAndView getRelate(@RequestParam(value = "curriculumTempNo",required = false) Integer curriculumNo){
		System.out.println(curriculumNo);
		ModelAndView view = new ModelAndView("tc/curriculumTemp/hardtempRelate");
		view.addObject("readRelate",curriculumBiz.queryCurriculum(curriculumNo));
		view.addObject("relateTempNo",curriculumNo);
		
		Map<Integer,String>   classTypeMap=dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_TYPE.getCode());
        Map<Integer,String>   classStep=dictionaryBiz.queryDictionaryByParent(DictionaryEnums.CURRICULUM_STEP.getCode());
        view.addObject("classTypeMap", classTypeMap);
        view.addObject("classStepMap", classStep);
        view.addObject("classType",  JSONObject.toJSONString(classTypeMap));
        view.addObject("classStep",  JSONObject.toJSONString(classStep));
        
		return view;
	}
	
	@RequestMapping(value="/saveRelate")
	@ResponseBody
	public String saveRelate(@RequestBody Map<String , Object> dataMap){
		return JSONObject.toJSONString(new CommonResult(curriculumTempBiz.saveRlate(dataMap)));
	}
	
	@RequestMapping(value="/saveHardRelate")
	@ResponseBody
	public String saveHardRelate(@RequestBody Map<String , Object> dataMap){
		
		return JSONObject.toJSONString(curriculumTempBiz.saveHardRlate(dataMap));
	}
}
